//
//  CZMainTabBarController.swift
//  05.08--weibo
//
//  Created by fennyYang on 16/5/12.
//  Copyright © 2016年 a. All rights reserved.
//

import UIKit

class CZMainTabBarController: UITabBarController
{

    override func viewDidLoad()
    {
        super.viewDidLoad()

        //1.定义闭包
        let compseCallback = { () -> () in
            // TODO: Model出控制器
            print("Model 出控制器")
        }

        let mainTabBar = CZMainTaBar()

        //2.传递闭包
        mainTabBar.composeCallback = compseCallback

        setValue(mainTabBar, forKey: "tabBar")


        setupChilderViewController()

    }

    //设置tabbar子控件
    func setupChilderViewController()
    {
        //首页
        let homeVC = CZHomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")

        //消息
        let messageVC = CZMessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")

        //发现
        let discoveryVC = CZDiscoveryViewController()
        addChildViewController(discoveryVC, title: "发现", imageName: "tabbar_discover")


        //我
        let profileVC = CZProfileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }


    //添加子控制器，设置标题和图片名称，并且包装导航控制器
    func addChildViewController(controller: UIViewController,title: String, imageName: String)
    {
        //设置标题
        controller.title = title

        //设置tabbar图片
        controller.tabBarItem.image = UIImage(named: imageName)

        //设置高亮图片
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

        //设置文字选中的颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)

        //包装导航控制器
        self.addChildViewController(UINavigationController(rootViewController: controller))

    }



}




























































